package com.my.quartz.boot.controller;

import com.my.quartz.boot.ScheduleUtils;
import com.my.quartz.boot.TaskException;
import com.my.quartz.boot.pojo.SysJob;
import com.my.quartz.boot.service.SysJobService;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Auto Generated
 *
 * @author ：Boy
 * @date ：Created in 2022-06-19
 * @description：
 * @modified By：
 */
@RestController
@RequestMapping("/job")
public class SysJobController {
    @Resource
    private SysJobService sysJobService;
    @Resource
    private ScheduleUtils scheduleUtils;
    @Resource
    private Scheduler scheduler;

    @PostMapping("/add")
    public Object add(@RequestBody SysJob entity) throws SchedulerException, TaskException {
        sysJobService.save(entity);
        scheduleUtils.createScheduleJob(scheduler, entity);
        return "ok";
    }
}
